package com.example.yichuangyun.mvvm.ui.activity.view;

import androidx.lifecycle.MutableLiveData;

import com.example.yichuangyun.config.Constant;
import com.example.yichuangyun.model.company.CollectDataModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseModel;
import com.example.yichuangyun.mvvm.di.retrofit.BaseNetCallback;
import com.example.yichuangyun.mvvm.ui.fragment.view.SearchCompanyViewModel;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyCollectViewModel extends SearchCompanyViewModel {

    public MutableLiveData<CollectDataModel> collectDataModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> delSuccessMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<String> keywords = new MutableLiveData<>();

    /**
     * 获取我的收藏列表
     */
    public void getMyCollectList(Map<String, Object> map) {
        map.put("queryType", 0);
        map.put("pageSize", Constant.pageSize);
        addSubscribe(mRetrofitHelper.getMyCollectList(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<CollectDataModel>() {

            @Override
            public void onSuccess(BaseModel<CollectDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode() && null != baseModel.getData()) {
                    collectDataModelMutableLiveData.setValue(baseModel.getData());
                }
            }
        }));
    }

    /**
     * 取消收藏企业
     */
    public void delCollectCompany(String id, String eid) {
        List<String> ids = new ArrayList<>();
        ids.add(id);
        List<String> eids = new ArrayList<>();
        eids.add(eid);
        Map<String, Object> map = new HashMap<>();
        map.put("codeList", ids);
        map.put("eids", eids);
        addSubscribe(mRetrofitHelper.delCollectCompany(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<String>() {

            @Override
            public void onSuccess(BaseModel<String> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    delSuccessMutableLiveData.setValue(baseModel.getData());
                }
            }
        }));
    }
}
